package com.zeedev.flyingsaucer.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import com.zeedev.flyingsaucer.global.UfoClubApp;
import mobi.zeedev.flyingsaucer.common.DataModule.FlyingSaucerConv;
import mobi.zeedev.flyingsaucer.common.DataModule.MetaBeer.DB_TYPES;

public class BeerDataHelper2 extends BeerDataHelperBase {
	 
	public static final String TAG = "BeerDataHelper";

    public BeerDataHelper2(Context context, String dbNameIn, int versionIn) {
    	super(context, dbNameIn, null, versionIn);
    }	
	
	@Override
	public void onCreate(SQLiteDatabase db) {     
        //Beers (Grand)
        db.execSQL(BeerDataHelper2.createStoresTable());
        db.execSQL(BeerDataHelper2.createStoresBeersTable());
        db.execSQL(BeerDataHelper2.createMemberBeersTable());
        db.execSQL(BeerDataHelper2.createBeersTable());
        db.execSQL(BeerDataHelper2.createMembersTable());

	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//Log.i(TAG,"Database upgrade called.");
        //Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + FlyingSaucerConv.Stores.StoreBeer.TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + FlyingSaucerConv.Stores.TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + FlyingSaucerConv.Beers.TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + FlyingSaucerConv.Members.TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + FlyingSaucerConv.Members.MemberBeer.TABLE);
        onCreate(db);
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		//TODO REMOVe THIS
		if (UfoClubApp.DEBUG_RESET_NEW_DATABASE) {
			onUpgrade(db, 0,0);	
		}
		

	}
	
	
	
	
	
	

	private static final String createMemberBeersTable() {
		String[] PROPERTIES_LIST = {
				FlyingSaucerConv.Members.MemberBeer.MEMBER_BEER_KEY,
				FlyingSaucerConv.Members.MemberBeer.BEER_DB_ID,
				FlyingSaucerConv.Members.MemberBeer.MEMBER_DB_ID,
				FlyingSaucerConv.Members.MemberBeer.CREATION_DATE,
				FlyingSaucerConv.Members.MemberBeer.UPDATED_DATE,
				FlyingSaucerConv.Members.MemberBeer.ACTIVE,
				FlyingSaucerConv.Members.MemberBeer.COMMENTS,
				FlyingSaucerConv.Members.MemberBeer.RATING,
				FlyingSaucerConv.Members.MemberBeer.TASTED_DATE,
				
		};
		DB_TYPES[] TYPES_LIST = {
				DB_TYPES.DB_KEY_AUTO,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_BOOLEAN,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER
		};
		return genericCreateCommand(FlyingSaucerConv.Members.MemberBeer.TABLE,PROPERTIES_LIST,TYPES_LIST);
		
	}
	
	private static final String createMembersTable() {
		String[] PROPERTIES_LIST = {
				FlyingSaucerConv.Members.MEMBERS_KEY,
				FlyingSaucerConv.Members.PASSWORD,
				FlyingSaucerConv.Members.STORE_NUMBER,
				FlyingSaucerConv.Members.CARD_NUMBER,
				FlyingSaucerConv.Members.PASSWORD_HASH,
				FlyingSaucerConv.Members.UFO_LOGIN_REMEMBER,
				FlyingSaucerConv.Members.UFO_LOGIN_AUTO_LOGIN,
				FlyingSaucerConv.Members.UFO_LOGIN_NON_MEMBER,
				FlyingSaucerConv.Members.UFO_HOME_NUMBER_BEERS,
				FlyingSaucerConv.Members.UFO_HOME_NUMBER_TOTAL_BEERS,
				FlyingSaucerConv.Members.UFO_HOME_USERNAME,
				FlyingSaucerConv.Members.UFO_HOME_NAME,
				FlyingSaucerConv.Members.UFO_MEMBER_ID,
				FlyingSaucerConv.Members.UFO_IS_CURRENT_USER,
				FlyingSaucerConv.Members.CREATION_DATE,
				FlyingSaucerConv.Members.UPDATED_DATE,
				FlyingSaucerConv.Members.BEERS_REFRESHED_DATE,
				FlyingSaucerConv.Members.UFO_ORIGIN_DATE,
				FlyingSaucerConv.Members.UFO_MOU_MEMBER
		};
		DB_TYPES[] TYPES_LIST = {
				DB_TYPES.DB_KEY_AUTO,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_BOOLEAN,
				DB_TYPES.DB_BOOLEAN,
				DB_TYPES.DB_BOOLEAN,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_BOOLEAN,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_BOOLEAN,
				
		};
		return genericCreateCommand(FlyingSaucerConv.Members.TABLE,PROPERTIES_LIST,TYPES_LIST);
		
	}

	public static final String createStoresBeersTable() {
		String[] PROPERTIES_LIST = {
				FlyingSaucerConv.Stores.StoreBeer.STORE_BEER_KEY,
				FlyingSaucerConv.Stores.StoreBeer.BEER_DB_ID,
				FlyingSaucerConv.Stores.StoreBeer.STORE_DB_ID,
				FlyingSaucerConv.Stores.StoreBeer.CREATION_DATE,
				FlyingSaucerConv.Stores.StoreBeer.UPDATED_DATE,
				FlyingSaucerConv.Stores.StoreBeer.ACTIVE,
				
		};
		DB_TYPES[] TYPES_LIST = {
				DB_TYPES.DB_KEY_AUTO,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_BOOLEAN
		};
		return genericCreateCommand(FlyingSaucerConv.Stores.StoreBeer.TABLE,PROPERTIES_LIST,TYPES_LIST);
		
	}
			
	public static final String createStoresTable() {
		
		String[] PROPERTIES_LIST = {
				FlyingSaucerConv.Stores.STORES_KEY,
				FlyingSaucerConv.Stores.NAME,
				FlyingSaucerConv.Stores.URL_NAME,
				FlyingSaucerConv.Stores.URL,
				FlyingSaucerConv.Stores.NUMBER,
				FlyingSaucerConv.Stores.UPDATED_DATE,
				FlyingSaucerConv.Stores.CREATION_DATE
//				StoresPreferencesModel.REFRESHED_BEERS
		};
		DB_TYPES[] TYPES_LIST = {
				DB_TYPES.DB_KEY_AUTO,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_STRING,
				DB_TYPES.DB_INTEGER,
				DB_TYPES.DB_INTEGER
//				DB_TYPES.DB_INTEGER
		};
		return genericCreateCommand(FlyingSaucerConv.Stores.TABLE,PROPERTIES_LIST,TYPES_LIST);
	}
	
	public static final String createBeersTable() {
		final String[] PROPERTIES_LIST = { 
			FlyingSaucerConv.Beers.BEER_ID, FlyingSaucerConv.Beers.COUNTRY_ID, FlyingSaucerConv.Beers.BREWER_ID, FlyingSaucerConv.Beers.STYLE_ID,
			FlyingSaucerConv.Beers.RAW_NAME, FlyingSaucerConv.Beers.NAME, FlyingSaucerConv.Beers.NAME_SUBSCRIPT,
			FlyingSaucerConv.Beers.CONTAINER, FlyingSaucerConv.Beers.BOTTLE, FlyingSaucerConv.Beers.DRAUGHT, FlyingSaucerConv.Beers.CAN,
//			Beers.DATE_ADDED, Beers.SIMPLE_DATE, Beers.TASTED,
			FlyingSaucerConv.Beers.DESCRIPTION, FlyingSaucerConv.Beers.CITY, FlyingSaucerConv.Beers.COUNTRY_NAME,
			FlyingSaucerConv.Beers.STYLE_NAME, FlyingSaucerConv.Beers.BREWER_NAME,
//			Beers.COMMENTS, Beers.RATING, 
			FlyingSaucerConv.Beers.AVERAGE_RATING,
			FlyingSaucerConv.Beers.BEERS_KEY
//			Beers.INTERNAL_DATE_ADDED,  , Beers.MEMBER_ID, Beers.STATUS
			};
	
	final DB_TYPES[] TYPES_LIST = { 
		DB_TYPES.DB_INTEGER, DB_TYPES.DB_INTEGER, DB_TYPES.DB_INTEGER, DB_TYPES.DB_INTEGER,
		DB_TYPES.DB_STRING, DB_TYPES.DB_STRING, DB_TYPES.DB_STRING,
		DB_TYPES.DB_STRING, DB_TYPES.DB_BOOLEAN, DB_TYPES.DB_BOOLEAN, DB_TYPES.DB_BOOLEAN,
//		DB_TYPES.DB_DATE, DB_TYPES.DB_STRING, DB_TYPES.DB_BOOLEAN,
		DB_TYPES.DB_STRING, DB_TYPES.DB_STRING, DB_TYPES.DB_STRING,
		DB_TYPES.DB_STRING, DB_TYPES.DB_STRING, 
		//DB_TYPES.DB_STRING, DB_TYPES.DB_INTEGER, 
		DB_TYPES.DB_INTEGER,
		DB_TYPES.DB_KEY_AUTO
//		DB_TYPES.DB_DATE, 
		
//		DB_TYPES.DB_INTEGER, DB_TYPES.DB_STRING
		};
	
		return genericCreateCommand(FlyingSaucerConv.Beers.TABLE,PROPERTIES_LIST,TYPES_LIST);
	}
	
	

	
	
	

	
	



 
}